package org.minuframework.file.upload.spring;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.minuframework.exception.ExceptionFailed;
import org.minuframework.file.upload.FileParamerConfigurer;
import org.minuframework.file.upload.FileTypesConfigurer;
import org.minuframework.file.upload.FileUploadType;
import org.springframework.web.multipart.MultipartFile;

import com.google.common.collect.Lists;

@Deprecated
public class FileUpload extends DefaultFileUpload {
    public FileUpload(FileParamerConfigurer fileUploadConfigurer, FileTypesConfigurer fileTypesConfigurer, String charset) {
        super(fileUploadConfigurer, fileTypesConfigurer, charset);
    }
    
    public static String upload(HttpServletRequest request, FileUploadType type) throws ExceptionFailed {
        return new FileUploadBuilder().setCharset("utf-8").create().fileUpload(request, type);
    }
    
    public static String uploadSafe(HttpServletRequest request, FileUploadType type) {
        try {
            return upload(request, type);
        } catch (ExceptionFailed localExceptionFailed) {}
        return null;
    }
    
    public static List<String> uploads(HttpServletRequest request, FileUploadType type) throws ExceptionFailed {
        return new FileUploadBuilder().setCharset("utf-8").create().fileUploadList(request, type);
    }
    
    public static List<String> uploadsSafe(HttpServletRequest request, FileUploadType type) {
        try {
            return uploads(request, type);
        } catch (ExceptionFailed localExceptionFailed) {}
        return Lists.newArrayList();
    }
    
    public static String upload(MultipartFile file, FileUploadType type) throws ExceptionFailed {
        return new FileUploadBuilder().setCharset("utf-8").create().fileUpload(file, type);
    }
    
    public static String uploadSafe(MultipartFile file, FileUploadType type) {
        try {
            return upload(file, type);
        } catch (ExceptionFailed localExceptionFailed) {}
        return null;
    }
    
    public static List<String> uploads(List<MultipartFile> files, FileUploadType type) throws ExceptionFailed {
        return new FileUploadBuilder().setCharset("utf-8").create().fileUpload(files, type);
    }
    
    public static List<String> uploadsSafe(List<MultipartFile> files, FileUploadType type) {
        try {
            return uploads(files, type);
        } catch (ExceptionFailed localExceptionFailed) {}
        return null;
    }
}
